import { createRouter, createWebHistory } from 'vue-router'

import { basicRoutes } from '@/router/routes'

import type { App } from 'vue'
import type { RouteRecordRaw } from 'vue-router'

export const router = createRouter({
  // 创建一个 hash 历史记录。
  history: createWebHistory(import.meta.env.VITE_PUBLIC_PATH), // createWebHashHistory
  // 应该添加到路由的初始路由列表。
  routes: basicRoutes as unknown as RouteRecordRaw[],
  // 是否应该禁止尾部斜杠。默认为假
  strict: true,
  scrollBehavior: () => ({ left: 0, top: 0 }),
})

// 配置路由器
export function setupRouter(app: App<Element>) {
  app.use(router)
}
